﻿using System.Text.Json;
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using FileCommon.Extensions;
using FileCommon.Models;

namespace FileCommon.Codecs;

public class ObjectDecoder : ByteToMessageDecoder
{
    protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
    {
        var data = new byte[input.ReadableBytes];
        input.ReadBytes(data);
        var jsonString = data.GetString();
        var message = JsonSerializer.Deserialize<UploadFileInfo>(jsonString);
        output.Add(message);
    }
}